package com.ygqh.baby.mapper;

import com.ygqh.baby.ao.*;
import com.ygqh.baby.model.BiChannelModel;
import com.ygqh.baby.model.*;
import com.ygqh.baby.po.YgUserBalance;
import com.ygqh.baby.po.YgUserBalanceDetail;
import com.ygqh.baby.po.YgUserBalanceDetailExample;
import org.apache.ibatis.annotations.Param;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author admin
 */
public interface YgUserBalanceDetailMapper {

	int countByExample(YgUserBalanceDetailExample example);

	int deleteByExample(YgUserBalanceDetailExample example);

	int deleteByPrimaryKey(Long id);

	int insert(YgUserBalanceDetail record);

	int insertSelective(YgUserBalanceDetail record);

	List<YgUserBalanceDetail> selectByExample(YgUserBalanceDetailExample example);

	YgUserBalanceDetail selectByPrimaryKey(Long id);

	int updateByExampleSelective(@Param("record") YgUserBalanceDetail record,
								 @Param("example") YgUserBalanceDetailExample example);

	int updateByExample(@Param("record") YgUserBalanceDetail record,
						@Param("example") YgUserBalanceDetailExample example);

	int updateByPrimaryKeySelective(YgUserBalanceDetail record);

	int updateByPrimaryKey(YgUserBalanceDetail record);

	List<YgUserBalanceDetail> selectBalanceDetail(@Param("queryInfo") QueryInfo queryInfo,
												  @Param("balanceType") String balanceType,
												  @Param("userId") Long userId, @Param("platformNo") String platformNo);

	List<YgUserBalanceDetail> selectBalanceDetailPage(@Param("queryInfo") QueryInfo queryInfo,
													  @Param("remark") String remark,
													  @Param("username") String username,
													  @Param("startDate") Date startDate,
													  @Param("endDate") Date endDate);

	Double selectBalanceDetailPageSumprice(@Param("username") String username, @Param("remark") String remark,
										   @Param("startDate") Date startDate, @Param("endDate") Date endDate);

	int selectBalanceDetailPageCount(@Param("username") String username, @Param("remark") String remark,
									 @Param("startDate") Date startDate, @Param("endDate") Date endDate);

	List<YgUserBalanceDetail> selectByCommissionIdPage(@Param("queryInfo") QueryInfo queryInfo,
													   @Param("userId") Long userId);

	int selectByCommissionIdPageCount(@Param("userId") Long userId);

	int countBalanceDetail(@Param("balanceType") String balanceType, @Param("userId") Long userId,
						   @Param("platformNo") String platformNo);

	List<YgUserBalanceDetailModel> selectBalanceDetailByType(@Param("queryInfo") QueryInfo queryInfo,
															 @Param("userId") Long userId,
															 @Param("balance") String balance,
															 @Param("preIncome") String preIncome,
															 @Param("platformNo") String platformNo);

	YgUserBalanceOrderDetailModel selectOrderBalanceDetail(@Param("balanceDetailId") Long balanceDetailId,
														   @Param("userId") Long userId);

	YgUserBalanceOrderInfo selectOrderBalanceDetailV2(@Param("ubdOrderId") String ubdOrderId,
													  @Param("balanceType") BalanceType balanceType,
													  @Param("operationType") String operationType,
													  @Param("userId") Long userId);

	int insertBalacneDetailByBatch(@Param("detailList") List<YgUserBalanceDetail> detailList);

	int addPriceTypeToBalance();

	List<YgUserBalanceDetail> findListByPriceTypeAndOrderIds(@Param("balanceType") BalanceType balanceType,
															 @Param("orderIds") Long[] orderIds);

	String selectBalanceDetailByOrderId(@Param("priceType") BalanceType priceType,
										@Param("rebateType") RebateType rebateType, @Param("orderId") String orderId);

	List<YgUserBalanceDetail> findUserBalanceDetailByUserId(@Param("userId") Long userId,
															@Param("balanceType") BalanceType balanceType);

	List<YgUserBalance> findUbdSumByUserIds(@Param("userIds") List<Long> userIds,
											@Param("priceType") BalanceType priceType);

	/**
	 * 查找企业用户列表By sourceCodeList
	 *
	 * @param sourceCodeList
	 * @return
	 */
	List<YgCompanyBalanceDetailModel> findCompanyListBySourceCodes(@Param("queryInfo") QueryInfo queryInfo,
																   @Param("sourceCodeList") List<String> sourceCodeList,
																   @Param("balanceType") String balanceType);

	Map<String, Object> findCompanyListBySourceCodesCount(@Param("sourceCodeList") List<String> sourceCodeList,
														  @Param("balanceType") String balanceType);

	Map<String, Object> findCompanyListBySourceCodesCountWithPrimary(@Param("sourceCodeList") List<String> sourceCodeList);

	/**
	 * 查找企业用户列表By UserId
	 *
	 * @param userId
	 * @return
	 */
	List<YgCompanyBalanceDetailModel> findCompanyListByUserId(@Param("queryInfo") QueryInfo queryInfo,
															  @Param("userId") Long userId,
															  @Param("balanceType") String balanceType);

	Map<String, Object> findCompanyListByUserIdCount(@Param("userId") Long userId,
													 @Param("balanceType") String balanceType);

	/**
	 * 企业返利，按员工聚合查询
	 *
	 * @param userId
	 * @param balanceType
	 * @param sourceCodeList
	 * @return
	 */
	List<YgCompanyBalanceCollectModel> findCompanyMoneyCollectByUser(@Param("userId") Long userId,
																	 @Param("balanceType") String balanceType,
																	 @Param("sourceCodeList") List<String> sourceCodeList);

	BiChannelModel selectChannelBi(@Param("sourceCode") String sourceCode);

	List<YgUserBalanceDetail> selectBalanceForCommissionDetail(@Param("userId") Long userId);

	Map<String, Object> selectTotalBalancePriceForCommission(@Param("userId") Long userId,
															 @Param("platformNo") String platformNo);

	int updateBalanceDetailByCommission(@Param("userId") Long userId, @Param("commissionId") Long commissionId,
										@Param("commissionStatus") CommissionStatus commissionStatus,
										@Param("isApply") Boolean isApply, @Param("maxId") Long maxId,
										@Param("platformNo") String platformNo);

	Map<String, Object> getOrderPriceBySourceCode(@Param("sourceCodeList") List<String> sourceCodeList);

	List<YgUserBalanceDetail> selectDetailByTime(@Param("balanceType") BalanceType balanceType,
												 @Param("startTime") Date startTime,
												 @Param("endTime") Date endTime);

	List<YgUserBalanceDetail> selectNoBalanceInComeListByOrderIds(@Param("orderIds") Long[] orderIds,
																  @Param("sendTime") Date sendTime);

	List<YgUserBalanceDetail> selectBalanceDetailsGroupByOrder(@Param("queryInfo") QueryInfo queryInfo,
															   @Param("userId") Long userId,
															   @Param("balanceType") BalanceType balanceType);

	List<YgUserBalanceDetail> findBalanceReturnDetailByOrderId(@Param("balanceType") BalanceType balanceType,
															   @Param("rebateType") RebateType rebateType,
															   @Param("orderId") Long orderId);

	int updateIsGived(@Param("isGived") Boolean isGived, @Param("idlList") List<Long> idlList);

	int updateIsGivedByOrderIdList(@Param("isGived") Boolean isGived, @Param("list") List<String> orderIdList);

	Map<String, Object> selectMyRebate(@Param("userId") Long userId, @Param("platformNo") String platformNo);

	List<YgUserRecommendModel> statisticsRecommendPrice(@Param("userId") Long userId,
														@Param("recommendUserIdList") List<Long> recommendUserIdList,
														@Param("platformNo") String platformNo);

	List<UserBalanceDetailModel> selectDetailList(@Param("queryInfo") QueryInfo queryInfo, @Param("userId") Long userId,
												  @Param("limitTime") Date limitTime, @Param("platformNo") String platformNo,
												  @Param("balanceType") BalanceType balanceType);
}